﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.Common;

namespace Light.Framework.Contract
{
    /// <summary>
    /// 数据库访问接口
    /// </summary>
    public interface IDbHelper
    {

        
        /// <summary>
        /// 数据库连接字符串
        /// </summary>
        string ConnectionString { get; set; }

        /// <summary>
        /// 数据库连接对象
        /// </summary>
        IDbConnection Connection { get; set; }

        /// <summary>
        /// 创建数据库连接对象
        /// </summary>
        /// <returns></returns>
        IDbConnection CreateDbConnection();

        /// <summary>
        /// 执行命令
        /// </summary>
        /// <param name="cmdType">命令类型（存储过程或SQL语句）</param>
        /// <param name="cmdText">SQL语句或存储过程名</param>
        /// <param name="cmdParms">MySqlCommand参数数组</param>
        /// <returns>返回受引响的记录行数</returns>
        int ExecuteNonQuery(CommandType cmdType, string cmdText, params IDataParameter[] cmdParms);

        /// <summary>
        /// 执行事务
        /// </summary>
        /// <param name="trans">MySqlTransaction对象</param>
        /// <param name="cmdType">命令类型（存储过程或SQL语句）</param>
        /// <param name="cmdText">SQL语句或存储过程名</param>
        /// <param name="cmdParms">MySqlCommand参数数组</param>
        /// <returns>返回受引响的记录行数</returns>
        int ExecuteNonQuery(DbTransaction trans, CommandType cmdType, string cmdText, params IDataParameter[] cmdParms);

        /// <summary>
        /// 执行命令，返回第一行第一列的值
        /// </summary>
        /// <param name="cmdType">命令类型（存储过程或SQL语句）</param>
        /// <param name="cmdText">SQL语句或存储过程名</param>
        /// <param name="cmdParms">MySqlCommand参数数组</param>
        /// <returns>返回Object对象</returns>
        object ExecuteScalar(CommandType cmdType, string cmdText, params IDataParameter[] cmdParms);

        /// <summary>
        /// 执行命令或存储过程，返回MySqlDataReader对象
        /// 注意MySqlDataReader对象使用完后必须Close以释放MySqlConnection资源
        /// </summary>
        /// <param name="cmdType">命令类型（存储过程或SQL语句）</param>
        /// <param name="cmdText">SQL语句或存储过程名</param>
        /// <param name="cmdParms">MySqlCommand参数数组</param>
        /// <returns></returns>
        IDataReader ExecuteReader(CommandType cmdType, string cmdText, params IDataParameter[] cmdParms);

        /// <summary>
        /// 执行命令或存储过程，返回DataSet对象
        /// </summary>
        /// <param name="cmdType">命令类型(存储过程或SQL语句)</param>
        /// <param name="cmdText">SQL语句或存储过程名</param>
        /// <param name="cmdParms">MySqlCommand参数数组(可为null值)</param>
        /// <returns></returns>
        DataSet ExecuteDataSet(CommandType cmdType, string cmdText, params IDataParameter[] cmdParms);
    }
}
